{extend name="admin@index_layout"/}
{block name="main"}
<form class="layui-form" method="post">

    <div class="layui-form-item">
        <label class="layui-form-label">路线类型</label>
        <div class="layui-input-block" id="is_c3">

            <input type="radio" name="row[type]" checked value="1" title="市外" lay-filter="ccc3">

            <input type="radio" name="row[type]" value="2" title="市内" lay-filter="ccc3">
        </div>
    </div>

    <div class="layui-form-item provice1">
        <label class="layui-form-label">出发省</label>
        <div class="layui-input-block">
            <select name="row[province]"  lay-filter="cccc62">
                <option value="">请选择省</option>
                {volist name="provice" id="vo"}
                <option value="{$vo.name}" <?php if( $vo['name'] == $data['provice']){ ?> selected <?php }?>>{$vo.name}</option>
                {/volist}
            </select>
        </div>
    </div>

    <div class="layui-form-item cc-city1">
        <label class="layui-form-label">出发市</label>
        <div class="layui-input-block">
            <select id="cc-city" name="row[city]"  lay-filter="cc-city">
                <option value="">请选择市</option>
                {volist name="city_list" id="vo"}
                <option value="{$vo.name}" <?php if( $vo['name'] == $data['city']){ ?> selected <?php }?>>{$vo.name}</option>
                {/volist}
            </select>
        </div>
    </div>



    <div class="layui-form-item">
        <label class="layui-form-label">目的省</label>
        <div class="layui-input-block">
            <select name="row[province2]" lay-verify="required" lay-filter="ccc62">
                <option value="">请选择省</option>
                {volist name="provice" id="vo"}
                <option value="{$vo.name}" <?php if( $vo['name'] == $data['provice']){ ?> selected <?php }?>>{$vo.name}</option>
                {/volist}
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">目的市</label>
        <div class="layui-input-block">
            <select id="c-city" name="row[city2]" lay-verify="required" lay-filter="c-city">
                <option value="">请选择市</option>
                {volist name="city_list" id="vo"}
                <option value="{$vo.name}" <?php if( $vo['name'] == $data['city']){ ?> selected <?php }?>>{$vo.name}</option>
                {/volist}
            </select>
        </div>
    </div>

    <div class="layui-form-item address" style="display: none">
        <label class="layui-form-label">详细地址</label>
        <div class="layui-input-block">
            <input type="text" name="row[address]"  autocomplete="off" placeholder="xx区县xx路xx号xxx"
                   class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">目的医院</label>
        <div class="layui-input-block">
            <select id="c-hospita" name="row[hospital_id]"  lay-filter="c-hospita">
                <option value="">请选医院</option>
                {volist name="hospita_list" id="vo"}
                <option value="{$vo.id}"" <?php if( $vo['id'] == $data['hospita_id']){ ?> selected <?php }?>>{$vo.name}</option>
                {/volist}
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">价格</label>
        <div class="layui-input-block">
            <input type="number" name="row[price]" lay-verify="required|priceNum" autocomplete="off" placeholder=""
                   class="layui-input" step="0.01" min="0.01">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">往返价格</label>
        <div class="layui-input-block">
            <input type="number" name="row[d_price]" lay-verify="required|priceNum" autocomplete="off" placeholder=""
                   class="layui-input" step="0.01">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input type="number" name="row[sort]" lay-verify="required|number" autocomplete="off" placeholder="排序"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item layer-footer">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit>立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
{/block}
{block name="script"}
<script type="text/javascript">
    layui.use(['yznForm', 'laydate','form'], function () {
        var yznForm = layui.yznForm,
            laydate = layui.laydate;

        var form = layui.form;
        yznForm.bindevent($("form.layui-form"));

        laydate.render({
            elem: '#ID-laydate'
        });

        form.on('select(ccc6)', function (data) {
            console.log(data.value);
            if (data.value == 3) {
                $(".c5").show();
            } else{
                $(".c5").hide();
            }
            form.render();
        });

        form.on('select(ccc62)', function (data) {
            console.log(data.value);
            $.ajax({
                type: "POST",//规定传输方式
                url: "{:url('getc_cate')}",//提交URL
                data: {'id': data.value},//提交的数据
                success: function (result) {
                    if (result.code == 200) {

                        $("#c-city").empty();
                        var str = "<option value>请选择市</option>";
                        $.each(result.data, function (i, val) {
                            str += '<option value=' + val.name + '>' + val.name + '</option>'
                        });
                        $("#c-city").append(str);

                        $("#c-city2").empty();
                        var str2 = "<option value>请选择区</option>";
                        $("#c-city2").append(str2);


                        $("#c-hospita").empty();
                        var str3 = "<option value>请选医院</option>";
                        $("#c-hospita").append(str3);


                        $("#c-department").empty();
                        var str4 = "<option value>请选科室</option>";
                        $("#c-department").append(str4);

                        layui.form.render('select');
                    }
                },
                error: function () {
                    alert("获取信息失败")
                }
            });
            form.render();
        });

        form.on('select(cccc62)', function (data) {
            console.log(data.value);
            $.ajax({
                type: "POST",//规定传输方式
                url: "{:url('getc_cate')}",//提交URL
                data: {'id': data.value},//提交的数据
                success: function (result) {
                    if (result.code == 200) {

                        $("#cc-city").empty();
                        var str = "<option value>请选择市</option>";
                        $.each(result.data, function (i, val) {
                            str += '<option value=' + val.name + '>' + val.name + '</option>'
                        });
                        $("#cc-city").append(str);

                        layui.form.render('select');
                    }
                },
                error: function () {
                    alert("获取信息失败")
                }
            });
            form.render();
        });

        form.on('select(c-city)', function (data) {
            $.ajax({
                type: "POST",//规定传输方式
                url: "{:url('get_hospit')}",//提交URL
                data: {'id': data.value},//提交的数据
                success: function (result) {
                    if (result.code == 200) {

                        $("#c-hospita").empty();
                        var str = "<option value>请选医院</option>";
                        $.each(result.data, function (i, val) {
                            str += '<option value=' + val.id + '>' + val.name + '</option>'
                        });
                        $("#c-hospita").append(str);

                        $("#c-department").empty();
                        var str4 = "<option value>请选科室</option>";
                        $("#c-department").append(str4);

                        layui.form.render('select');
                    }
                },
                error: function () {
                    alert("获取信息失败")
                }
            });
            form.render();
        });

        form.on('select(c-city2)', function (data) {
            $.ajax({
                type: "POST",//规定传输方式
                url: "{:url('get_hospit')}",//提交URL
                data: {'id': data.value},//提交的数据
                success: function (result) {
                    if (result.code == 200) {
                        $("#c-hospita").empty();
                        var str = "<option value>请选医院</option>";
                        $.each(result.data, function (i, val) {
                            str += '<option value=' + val.id + '>' + val.name + '</option>'
                        });
                        $("#c-hospita").append(str);

                        $("#c-department").empty();
                        var str4 = "<option value>请选科室</option>";
                        $("#c-department").append(str4);

                        layui.form.render('select');
                    }
                },
                error: function () {
                    alert("获取信息失败")
                }
            });
            form.render();
        });

        form.on('select(c-hospita)', function (data) {
            console.log(data);
            $.ajax({
                type: "POST",//规定传输方式
                url: "{:url('get_department')}",//提交URL
                data: {'id': data.value},//提交的数据
                success: function (result) {
                    if (result.code == 200) {
                        $("#c-department").empty();
                        var str = "<option value>请选科室</option>";
                        $.each(result.data, function (i, val) {
                            str += '<option value=' + val.id + '>' + val.name + '</option>'
                        });
                        $("#c-department").append(str);
                        layui.form.render('select');
                    }
                },
                error: function () {
                    alert("获取信息失败")
                }
            });
            form.render();
        });

        form.on('radio(ccc3)',function (data){
            if($('#is_c3 input[name="row[type]"]:checked ').val() ==1){
                $(".provice1").show();
                $(".cc-city1").show();
                $(".address").hide();
            }else{
                $(".provice1").hide();
                $(".cc-city1").hide();
                $(".address").show();

            }
            form.render();
        });

    });
</script>
{/block}